﻿//登录
function WapLogin(name, password) {
    if (name == '') {
        Alert("请填写用户名")
        return;
    }
    if (password == '') {
        Alert("请填写密码")
        return;
    }

    if ($_2("savePwd").checked) {
        SetCookie('login_name', name);
    }

    var param = "username=" + name + "&userpassword=" + password + "&login_type=5&action=api_login&domain=";
    AjaxJsonp("http://www.711688.com.cn/api/login.aspx", param, function (data) {
        if (data.Code != 200) {
            Alert(data.Message)
            return;
        }
        loginByDYB(name);
    });
}

//订阅宝方式登录
function loginByDYB(name) {
    AjaxStart(api_domain + "api/account/GetUserFromOpenId?server=dyb&openId=" + name, "", function (data) {
        if (!isSuccess(data)) return;
        if (data.Data == null) {
            Alert("用户名不存在");
            return
        }
        loginIn(data.Data.StoreId, name);
        var url = getQueryString("backurl") != "" ? decodeURIComponent(getQueryString("backurl")) : PageUrl.Order_List;
        toUrl(url);
    });
}


//登录状态保持
function loginIn(userid, name) {
    SetCookie("userid", userid);
    SetCookie("name", name);
}

//退出,清理状态
function loginOut() {
    delCookie("userid");
    delCookie("name");
}

function loadInfo() {
    $("#name").val(getCookie("login_name"));
}